package com.everydayflash.fp10 {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shader;
	import flash.filters.ShaderFilter;
	import flash.geom.Point;
	import flash.utils.ByteArray;	

	/**
	 * @author bartekd
	 */
	public class CubeMaterial {
		
		[Embed (source="wood.jpg")]
		private var Texture:Class;
		public var _texture:BitmapData;
		public var clip:Bitmap;
		public var shadedTexture:Shader;

		[Embed (source="cubeShading.pbj", mimeType="application/octet-stream")]
		private var CubeShading:Class;
		private var template:BitmapData;

		public function CubeMaterial() {
			clip = new Texture();
			template = clip.bitmapData;
			_texture = template.clone();
			shadedTexture = new Shader(new CubeShading() as ByteArray);
			shadedTexture.data.side.value = [256.0];
			shadedTexture.data.darkness.value = [0.25];
			shadedTexture.data.src.input = texture;
		}
		
		public function get texture():BitmapData {
			_texture = template.clone();
			_texture.applyFilter(template, template.rect, new Point(), new ShaderFilter(shadedTexture));
			return _texture;
		}
	}
}
